package com.huazai.yangge.completable.future;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author 华仔
 * @date 2024/2/21
 */
public class CompletableFutureDemo {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //final CompletableFuture<Void> completableFuture = CompletableFuture.runAsync(() -> {
        //    System.out.println(Thread.currentThread().getName());
        //});

        //final ExecutorService executorService = Executors.newFixedThreadPool(3);
        //final CompletableFuture<Void> completableFuture = CompletableFuture.runAsync(() -> {
        //    System.out.println(Thread.currentThread().getName());
        //}, executorService);
        //executorService.shutdown();

        final ExecutorService executorService = Executors.newFixedThreadPool(3);
        final CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> {
            System.out.println(Thread.currentThread().isDaemon() ? "守护线程" : "不是守护线程");
            return "我的返回";
        });
        final String s = completableFuture.get();
        System.out.println("s = " + s);
        executorService.shutdown();
    }
}



